package com.zisu.aradvertising.utils;

import com.aliyuncs.IAcsClient;
import com.aliyuncs.exceptions.ClientException;
import com.aliyuncs.exceptions.ServerException;
import com.aliyuncs.http.FormatType;
import com.aliyuncs.mts.model.v20140618.QuerySmarttagJobRequest;
import com.aliyuncs.mts.model.v20140618.QuerySmarttagJobResponse;
import com.aliyuncs.mts.model.v20140618.SubmitSmarttagJobRequest;
import com.aliyuncs.mts.model.v20140618.SubmitSmarttagJobResponse;
import com.zisu.aradvertising.config.OSSConfiguration;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.stereotype.Component;

@Configuration
@Component
public class VideoUtil {
    public static Logger log = LoggerFactory.getLogger(VideoUtil.class);

    @Autowired
    private OSSConfiguration ossConfiguration;

    @Autowired
    private IAcsClient IAcsClient;

    public String submitSmarttagJob(String filePath, String title) {

        IAcsClient client = IAcsClient;

        // 创建request，并设置参数。
        SubmitSmarttagJobRequest request = new SubmitSmarttagJobRequest();
        request.setInput(filePath);      // 需要分析的文件OSS地址
        request.setPipelineId("dcefb897726643bc831d25f14df3861d"); // 管道ID，若填空，表示默认管道
        request.setTitle(title);        // 文件标题
//        request.setContent("<yourContent>");    // 文件内容描述，选填
        request.setAcceptFormat(FormatType.JSON);
        String JobId = "";

        try {
            // 接收请求结果response。
            SubmitSmarttagJobResponse response = client.getAcsResponse(request);
            JobId = response.getJobId();
            return JobId;
            //            System.out.println(new Gson().toJson(response));
        } catch (ServerException e) {
            e.printStackTrace();
        } catch (ClientException e) {
            System.out.println("ErrCode:" + e.getErrCode());
            System.out.println("ErrMsg:" + e.getErrMsg());
            System.out.println("RequestId:" + e.getRequestId());
        }
        return JobId;
    }

    public QuerySmarttagJobResponse querySmarttagJob(String JobId) {
        // 创建IAcsClient实例，需要补充AK信息和需要使用的服务区域，区域以beijing为例。
        IAcsClient client = IAcsClient;

        // 创建request，并设置参数。
        QuerySmarttagJobRequest request = new QuerySmarttagJobRequest();
        request.setJobId(JobId);
        QuerySmarttagJobResponse response = null;
        try {
            // 接收请求结果response。
            response = client.getAcsResponse(request);
            return response;
//            System.out.println(new Gson().toJson(response));
        } catch (ServerException e) {
            e.printStackTrace();
        } catch (ClientException e) {
            System.out.println("ErrCode:" + e.getErrCode());
            System.out.println("ErrMsg:" + e.getErrMsg());
            System.out.println("RequestId:" + e.getRequestId());
        }
        return response;
    }


}
